import axios from 'axios'

export default {
  namespaced: true,
  state: {
    catagtory: [],
    currentCatagtory: ''
  },
  mutations: {
    updateCatagtory (state, payload) {
      state.catagtory = payload
    },
    updateCurrentCatagtory (state, payload) {
      state.currentCatagtory = payload
    }
  },
  actions: {
    async getCatagtory (context) {
      // const data = await axios.get('http://toutiao.itheima.net/v1_0/channels')
      // const payload = data.data.data.channels

      const { data: { data: { channels: payload } } } = await axios.get('http://toutiao.itheima.net/v1_0/channels')

      context.commit('updateCatagtory', payload)
      context.commit('updateCurrentCatagtory', payload[0].id)
    }
  }
}
